#!/usr/bin/python
# -*- coding: utf-8 -*-
# @name             : 异常捕获装饰器
# @author           : OneYoung
# @create           : 2024/02/04
# @version          : v1.0
# @desc             :

import traceback
from functools import wraps
from utils.log_record import logger


def error_handler(func):
    """
    异常捕获装饰器
    :param func: 执行函数
    :return:
    """

    @wraps(func)  # 消除装饰器对原函数造成的影响
    def monitor(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except Exception as ec:
            logger.error(str(ec), traceback.format_exc())

    return monitor
